################# Import Data #################

roper <- c("Data/Roper Data.csv")
roper <- lapply(roper, read.csv) %>% bind_rows()

# Edited value - consistent with LHostile_Cumulative for next month
roper$Hostile_Cumulative <- ifelse(roper$X == 56, 268, roper$Hostile_Cumulative)

roper <- roper[(roper$Roper != "31088932"),]
names(roper)[names(roper) == 'mdate'] <- 'start_month_date'
names(roper)[names(roper) == 'war_duration'] <- 'war_duration_days'

################# Analysis #################

# Create percent variables
roper$nrespondents <- roper$Withdraw+roper$Notwithdraw
roper$percwithdrawd <- roper$Withdraw/roper$nrespondents
roper$percwithdraw <- roper$percwithdrawd*100

# Create binary variables
roper$bEnemyVictory<-ifelse(roper$EnemyVictory=="Yes",1,0)
roper$bDeescalationOption<-ifelse(roper$DeescalationOption=="Yes",1,0)
roper$bOnesidedquestion<-ifelse(roper$Onesidedquestion=="Yes",1,0)

# Code each campaign as numeric
roper$numcampaign2 <- ifelse(roper$Campaign2=="Afghanistan",1,"")
roper$numcampaign2[roper$Campaign2 == "Gulf War"] <- 2
roper$numcampaign2[roper$Campaign2 == "Iraq"] <- 3
roper$numcampaign2[roper$Campaign2 == "Lebanon"] <- 4
roper$numcampaign2[roper$Campaign2 == "Vietnam"] <- 5
roper$numcampaign2[roper$Campaign2 == "Other"] <- 6

write.csv(roper,"Data/Roper Data for Analysis.csv",row.names=FALSE)

